package com.example.a10908.retorfitrxjava.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a10908.retorfitrxjava.R;
import com.example.a10908.retorfitrxjava.model.bean.ListBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 10908 on 2016/12/16.
 */

public class MianListViewAdapter extends BaseAdapter {
    private Context context;
    private List<ListBean.DataBean> list;

    public MianListViewAdapter(Context context, List<ListBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.text1.setText(list.get(position).getName());
        Picasso.with(context).load(list.get(position).getCheckicon()).into(holder.image);
        return convertView;
    }

    public static class ViewHolder {
        public View rootView;
        public TextView text1;
        public ImageView image;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.text1 = (TextView) rootView.findViewById(R.id.text1);
            this.image = (ImageView) rootView.findViewById(R.id.image);
        }

    }
}
